window.addEvent('domready', function() {
	/*****************************************************
	*					  ORBITAL
	******************************************************/

	
	var radius = 100.0;
	
	// distribute
	
	var orbs = $$('#orbital .orb');
	var da = Math.PI * 2.0 / orbs.length;
	var angle = 0.0;
	
	// original sizes
	var sizeX = orbs[0].getSize().size.x;
	var sizeY = orbs[0].getSize().size.y;
	var fontSize = $('orbital').getStyle('font-size').toInt();
	
	// orbital offset
	var szOffset = $('orbital').getSize().size;
	var offsetX = (szOffset.x - sizeX)/2.0;
	var offsetY = (szOffset.y - sizeY)/2.0;
	
	
	var fx = new Fx.Elements(orbs);
	var fx2 = new Fx.Elements($$('.orb_image'));
	var a = {};
	var b = {};
	
	// index of the fore-front orb
	var index = 0;
	
	
	function orbitalize() {
		orbs.each( function(orb, i) {
			szScalar = ((Math.cos(angle + (i+index)*da) / 4.0) + 0.75); 
			a[i] = {
				'top'		: (Math.cos(angle + (i+index)*da) * radius / 4 + offsetY).round(),
				'left'		: (Math.sin(angle + (i+index)*da) * radius + offsetX).round(),
				'font-size'	: (szScalar * fontSize).round()
			}
			
			b[i] = {
				'width' : szScalar * sizeX,
				'height': szScalar * sizeY
			}
			
			orb.setStyle('z-index', (szScalar * 100).round());
		});
		
		fx.start(a);
		fx2.start(b);
	}
	
	orbitalize();

	
	$('orbital_left').addEvent('click', function () {
		index++;
		orbitalize();
	});
	
	$('orbital_right').addEvent('click', function () {
		index--;
		orbitalize();
	});
});